package com.crois.barrier.web.plugin.route;

import com.crois.barrier.common.enums.PluginEnum;
import com.crois.barrier.common.enums.PluginTypeEnum;
import com.crois.barrier.plugin.BarrierPlugin;
import com.crois.barrier.plugin.BarrierPluginChain;
import com.crois.barrier.web.cache.CacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author Hou Ze Yu
 * @description 路由重写插件
 * @date 2020/7/14
 */
public class RewritePlugin implements BarrierPlugin {

    private static  final Logger LOGGER = LoggerFactory.getLogger(RewritePlugin.class);

    private CacheManager cacheManager;

    public RewritePlugin(CacheManager cacheManager) {
        this.cacheManager = cacheManager;
    }


    @Override
    public Mono<Void> execute(ServerWebExchange exchange, BarrierPluginChain chain) {
        LOGGER.info("[开始执行：RewritePlugin]");
        LOGGER.info("[执行完成：RewritePlugin]");
        return chain.execute(exchange);
    }

    @Override
    public PluginTypeEnum pluginType() {
        return PluginTypeEnum.ROUTE;
    }

    @Override
    public String name() {
        return PluginEnum.REWRITE.getName();
    }

    @Override
    public int order() {
        return PluginEnum.REWRITE.getCode();
    }

    @Override
    public Boolean skip(ServerWebExchange exchange) {
       return false;
    }
}

